package com.itheima.health.controller;

import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import com.itheima.health.service.RoleService;
import com.itheima.health.vo.RoleVO;
import com.itheima.health.vo.UserVO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {
    @Reference
    private RoleService roleService;

    @Reference
    private PermissionService permissionService;

    @PostMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean pageBean){
       PageResult rolePage=roleService.findPage(pageBean);
       return new Result(rolePage);
    }

    @GetMapping("/findAllpermissions")
    public Result findAllpermissions(){
        List<Permission> list = permissionService.list();
        return new Result(list);
    }
    @GetMapping("/findAllpermissionIds/{id}")
    public Result findAllpermissionIds(@PathVariable("id")Integer id){
        RoleVO roleVO= roleService.findAllpermissionIdsAndPermission(id);
        return new Result(roleVO);
    }

    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody RoleVO roleVO){
        Boolean add = roleService.addAndUpdate(roleVO);
        return new Result(add);
    }
}
